package com.blockmeta.bbs.businesslibrary.widget.chartview.Axis;


import com.blockmeta.bbs.baselibrary.utils.FormatUtil;
import com.blockmeta.bbs.businesslibrary.widget.chartview.CandleData;
import com.blockmeta.bbs.businesslibrary.widget.chartview.ChartData;
import com.blockmeta.bbs.businesslibrary.widget.chartview.Layer.Layer;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DepthCoordinate extends Coordinate {
    @Override
    public void setData(ChartData pData) {
        List<Point> tXList = new ArrayList<Point>();
        List<Point> tYList = new ArrayList<Point>();

        if (pData != null) {
            ChartData.ChartPeroid mChartType = pData.getChartPeroid();
            Layer.ChartTypeEnum tLayerType = m_callback.getCharTypeEnum();
            m_ScaleFactor = m_callback.getScaleFactor();
            int tYTagCount = m_callback.getYTagCount();

            List<CandleData> tDataList = pData.getCandleData();

            int tStartIndex = pData.m_dataIndex;//为数据index的位置
            m_nStartIndex = pData.m_dataIndex;
            int nXTagCount = m_callback.getXTagCount();

            float tMaxValue = 0.f;
            float tMaxPrice = 0.f;
            float tMinPrice = 0.f;
            Date tStrFlagDate = null;

            tSymBol = pData.getSymbol();

            boolean tSimpleMode = m_callback.isSimpleMode();
            int lastXIndex = 0;

            int minCount = Math.min(m_nStartIndex + m_callback.getDisplayCount(), pData.getCandleData().size());


            tStartIndex = 0;
            m_nStartIndex = 0;
            minCount = pData.getCandleData().size();
            m_nQueryCount = pData.getCandleData().size();//为一屏幕显示的个数

            m_bDigit = 2;//价格小数位数
            if (tSymBol != null) {
                m_bDigit = tSymBol.getDigit();
            }

            int xSize = 3;
            int interval = (minCount - tStartIndex) / xSize;
            int iCurValue = tStartIndex + interval;
            for (int i = tStartIndex; i < minCount; i++) {
                CandleData tData = tDataList.get(i);

                float tHighVolumn = -1;
                float tHigh = -1;
                float tLow = -1;

                tHighVolumn = tData.m_lVolume;
                tHigh = (float) tData.getDbClose();
                tLow = (float) tData.getDbClose();


                if (i == tStartIndex) {
                    tMaxValue = tHighVolumn;
                    tMaxPrice = tHigh;
                    tMinPrice = tLow;
                } else {
                    if (tHigh >= tMaxPrice) {
                        tMaxPrice = tHigh;
                    }
                    if (tLow <= tMinPrice) {
                        tMinPrice = tLow;
                    }
                    if (tHighVolumn >= tMaxValue) {
                        tMaxValue = tHighVolumn;
                    }
                }


                if (i >= iCurValue && tXList.size() < (xSize - 1)) {
                    String max = FormatUtil.getFormatString(tData.getDbClose(), m_bDigit);
                    tXList.add(new Point(0, 0, 0, 0, true, max, (i + 1 - tStartIndex)));
                    iCurValue += interval;
                }


            }


            m_nYIntervalCount = 6;
            m_nYIntervalStandard = tMaxValue / (m_nYIntervalCount - 1);
            int m_nDigit = FormatUtil.getDigitNumber(String.valueOf(tMaxValue));
            float curValue = 0.f;
            for (int i = 0; i < m_nYIntervalCount; i++) {
                String max = FormatUtil.getFormatString(curValue, m_nDigit);

                if(i == 0)
                {
                    max = "";
                }
                tYList.add(new Point(0, 0, 0, 0, true, max, i));
                curValue += m_nYIntervalStandard;
            }


            m_fMaxValue = tMaxValue;
            m_fMinValue = 0;
        }
        m_xAxis.setPointList(tXList);
        m_yAxis.setPointList(tYList);
    }

}
